
#ifndef __CMD_MNG_CLIENT_HPP__
#define __CMD_MNG_CLIENT_HPP__

#include "khan.hpp"
#include "vty.hpp"
#include "command_manager_if.hpp"
#include "ipc_session.hpp"
#include "vty_ipc_msg.hpp"
#include "cmd_mng_session.hpp"

class cmd_agent_mng;
typedef boost::shared_ptr<cmd_agent_mng> cmd_agent_mng_ptr;

/* FIXME: change class name..... */
class cmd_agent_mng
:public command_manager_if, 
public boost::enable_shared_from_this<cmd_agent_mng>,
private boost::noncopyable       
{
public:
    static cmd_agent_mng_ptr instance();

    ~cmd_agent_mng();

    void run();
    void stop();  

    bool add_mode(const std::string name, 
            const std::string prompt, bool is_auth = false);
    bool add_command( const std::string mode, 
            const std::string cmdfmt, const std::string help, ExcuteHandle run);

	void show_agent_runcfg(vty_ptr vty);
	bool send_alarm(const std::string data);	/* FIXME: */

    bool get_function(__u64 function_id, ExcuteHandle& function);
    bool get_dialog(int vty_id, DialogHandle& function);
    bool set_dialog(int vty_id, DialogHandle& function);
    
private:
    typedef std::map<__u64, ExcuteHandle> function_map_t;
    typedef std::map<int, DialogHandle> dialog_map_t;
    typedef function_map_t::iterator    function_map_iterator;
    typedef dialog_map_t::iterator      dialog_map_iterator;

    cmd_agent_mng();

    static cmd_agent_mng_ptr _instance;
    static boost::mutex _singletone_lock;

    io_service  _io_service;
    cmd_mng_session_ptr _session;
    vty_ipc_msg _ipcmsg;
    function_map_t  _function_map;
    dialog_map_t    _dialog_map;
    boost::mutex    _io_lock;
    boost::mutex    _function_lock;
    boost::mutex    _dialog_lock;
	__u64			_func_num;
};

#endif
